package com.feng.cloud.common.handler;

import com.feng.cloud.common.exception.auth.AuthStatus;
import com.feng.cloud.common.response.BaseResponse;
import com.feng.cloud.common.utils.WebUtils;
import org.springframework.http.MediaType;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.web.AuthenticationEntryPoint;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @ClassName FengAuthExceptionEntryPoint
 * @Description TODO
 * @Author Better Feng
 * @Date 2019/12/20 15:03
 * @Version 1.0
 **/
public class FengAuthExceptionEntryPoint implements AuthenticationEntryPoint {
    @Override
    public void commence(HttpServletRequest request, HttpServletResponse response, AuthenticationException authException) throws IOException, ServletException {
        WebUtils.makeResponse(response, MediaType.APPLICATION_JSON_VALUE, HttpServletResponse.SC_FORBIDDEN,
                new BaseResponse(AuthStatus.UNAUTHORIZED));
    }
}
